package com.exam.system.controller;

import com.exam.system.entity.ExamUser;
import com.exam.system.entity.ResponseEntity;
import com.exam.system.service.ExamStudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api("角色管理类")
@RestController
@CrossOrigin
@RequestMapping("/student/")
public class ExamStudentController {
    @Autowired
    private ExamStudentService examStudentService;

    @RequestMapping("studentlist")
    public ResponseEntity<List<ExamUser>> findAllStudent(Integer pageNum, Integer pageSize ) {
        PageHelper.startPage(pageNum, pageSize);
            List<ExamUser> list = examStudentService.findAllStudent();
        PageInfo<ExamUser> info   = new PageInfo<>(list);
        return new ResponseEntity(200, "", info);
    }

    @ApiImplicitParam(name = "id", value = "考试信息id")
    @ApiOperation(value = "查看某个角色信息")
    @RequestMapping("/studentview")
    public ResponseEntity<ExamUser> studentView(ExamUser examUser) {
        try {
            examStudentService.findStudentById(examUser.getId());
            return new ResponseEntity<>(200, "查看成功", null);
        } catch (Exception e) {
            return new ResponseEntity<>(400, "查看失败", null);
        }
    }

    @ApiImplicitParam(name = "ExamStudent", value = "考试信息id")
    @ApiOperation(value = "修改一条角色信息")
    @RequestMapping("/studentupdate")
    public ResponseEntity<ExamUser> examInfoUpdate(@RequestBody ExamUser examUser) {
       examStudentService.updateById(examUser);
        System.out.println(examUser);
        return new ResponseEntity<>(200, "修改成功", null);

    }



    //添加
    @ApiImplicitParam(name = "examInfo", value = "考试信息实体类")
    @ApiOperation(value = "添加考试方法")
    @RequestMapping("/add")
    public ResponseEntity<ExamUser> examInfoAdd(@RequestBody ExamUser examUser) {
        examStudentService.insertStudent(examUser);
        return new ResponseEntity<>(200, "添加成功", null);
    }
}
